# 文件操作


# 操作文件第一种方式 （读文件）
# f = open('E:\\shujia\\十九期\\python\\test1.txt', 'r', encoding='UTF-8')
# content = f.read()
# print(content)
# # 释放资源
# f.close()
# 释放资源后调用
# content = f.read()  # I/O operation on closed file.
# print(content)

# # 操作文件的第二种方式
# with open('E:\\shujia\\十九期\\python\\test1.txt', 'r', encoding='UTF-8') as f2:
#     content = f2.read()
#     print(content)
# with打开文件后会自动关闭
# content2 = f2.read()  # I/O operation on closed file.
# print(content2)
# #
# read()方法中加入数字表示读取字符的字符数
# with open('E:\\shujia\\十九期\\python\\test1.txt', 'r', encoding='UTF-8') as f2:
#     content = f2.read(6)
#     print(content)
#
# 写数据，如果文件不存在，会自动创建
# with open('E:\\projects\\PycharmProjects\\bigdata19\\b.txt', 'w', encoding='UTF-8') as f2:
#     f2.write('你好，世界！')

# # 追加写入操作
# with open('E:\\projects\\PycharmProjects\\bigdata19\\b.txt', 'a', encoding='UTF-8') as f2:
#     f2.write('\n')
#     f2.write('你好，世界2！')
#     f2.write('\r\n')
#
# # 读取特定的文件并操作
# with open('E:\\projects\\PycharmProjects\\bigdata19\\b.txt', 'r', encoding='UTF-8') as f3:
#     # 读取所有行
#     content2 = f3.readlines()
#     # print(content2, type(content2))
#     for line in content2:
#         # 去除换行符
#         line = line.strip()
#         # 以逗号分割
#         strings = line.split("，")
#         print("值是%s%s,我叫%s" % (strings[0], strings[1], 'xiaohu'))
# print(line)
#
# list2 = [['3', 'c1', 'c2', 'c3', 'c4', 'c5'], ['4', 'd1', 'd2', 'd3', 'd4', 'd5']]
#
# with open('f.txt', 'w', encoding='UTF-8') as f4:
#     for i in list2:
#         # 每个元素之间用逗号进行连接
#         con = ','.join(i)
#         con = con + '\r\n'  # 当+两边是字符串的时候，是做字符串拼接的
#         # print(con, type(con))
#         f4.write(con)

#
# # 函数定义和使用
# # 注意事项 在python文件的任意位置都可以定义和调用函数，函数不调用，就不执行
def sum(x, y):
    return x + y


sumNum = sum(1, 2)
print(sumNum)

sum2 = lambda x, y, z: x + y + z
print(sum2(1, 2, 3))

# scala
